package com.service;

import com.dao.AnimeDao;
import com.entity.Anime;
import com.entity.AnimeKira;
import com.entity.AnimeType;
import com.entity.BatchDelete;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author WZ
 * @version 1.0
 * @date 2021/8/18 16:34
 */
@Service
public class AnimeService {
@Autowired
private AnimeDao animeDao;

    @Autowired
    private SqlSession sqlSession;

//查询角色信息的方法
    public List<AnimeKira> findKira(String name){

        List<AnimeKira> reslist=animeDao.findKira(name);
        return reslist ;
    }
   //添加角色的方法
    public void addKiaRa(AnimeKira kira){
        animeDao.addKiaRa(kira);
    }
    //删除角色的方法
    public  void deleteKiaRa(AnimeKira kira){

        animeDao.deleteKiaRa(kira);
    }

    //修改角色的方法
    public void updateKiaRa(AnimeKira kira){

        animeDao.updateKiaRa(kira);
    }
    //根据id查找角色 用于辅助修改方法
    public List<AnimeKira> findKiraByid(Integer id){
        return animeDao.findKiraById(id);
    }

    //查询动画列表
    public List<Anime> findAllAnime(String name){
        return  animeDao.findAllAnime(name);
    }
    //添加动画列表
    public void  addAnime(Anime anime){
        animeDao.addAnime(anime);
    }

    public void updateAnime(Anime anime){
        animeDao.updateAnime(anime);
    }
    public void  deleteAnime(Anime anime){
        animeDao.deleteAnime(anime);
    }

    //批量删除
    public void deleteKiaRas(BatchDelete ids){
          AnimeDao mapper=sqlSession.getMapper(AnimeDao.class);

          for (int i :ids.getIds()){

              mapper.deleteKiaRa(new AnimeKira(i));
          }

    }

    //动画类型字典表
    public List<AnimeType> animeTypeTable(){

        List<AnimeType> allAnimeType = animeDao.findAllAnimeType();
        return  allAnimeType;

    }
}
